#include "BridgeLeftEntity.h"
#include "EffectManager.h"



BridgeLeftEntity::BridgeLeftEntity(int id, int type, double x, double y)
{
	//init object data
	_data = new BridgeData(id, type, x + 1, y);
	state = BridgeState::STATE_Assign;
	_data->sprites->currentSprite->setStartEnd(0,2);
	_counter = 0;
	//
}

void BridgeLeftEntity::update(long time)
{
	if(state == BridgeState::STATE_End)
	{
		return;
	}
	Rect* rect = GameDeviceSingleton::getInstance()->getPlayerRect();
	if(rect->X >= _data->rect->X - _data->rect->Width && state == BridgeState::STATE_Assign)
	{

		state = BridgeState::STATE_Fire;

		_data->sprites->currentSprite->setStartEnd(2,3);

		this->getAbstractData()->canInteract = false;
		EffectManager::currentBridgeIndex = _data->id;
		EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Bridge_Fier, this->_data->getRect()->X + (160/2 - this->_data->getRect()->Width) - 5, this->_data->getRect()->Y + 3);
		//EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Bridge_Fier, this->_data->getRect()->getRight() - 80 + 58/2, this->_data->getRect()->Y + (29 - 9)/2);
	}
	else if(state == BridgeState::STATE_Fire)
	{
		_counter++;
		if(_counter == TIME_DELAY)
		{
			state = BridgeState::STATE_End;
			EffectManager::currentBridgeIndex++;
		}
	}
	else
	{
		_data->sprites->updateCurrent();
	}
}

void BridgeLeftEntity::draw(long time)
{
	if(state == BridgeState::STATE_End)
	{
		return;
	}
	else
	{
		_data->sprites->draw();
	}
	//_data->sprites->draw();
}

AbstractData* BridgeLeftEntity::getAbstractData()
{
	return _data;
}
